package com.gzedu.frame.db;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * 
*<font color="#0000FF"> 
*<p>数据库</p>
*<p>初始化建表、删除表</p>
*</font>
* @Title: BaseDateBase.java
* @Package com.gzedu.common.logic.db
* @company:		广州远程教育中心有限公司
* @author :		戴俊林
* @date 2012-8-28 下午5:22:52
* @version V1.0
 */
public class BaseDateBase extends SDSQLiteOpenHelper {

	private List<Map<String, String>> tableList;

	/**
	 * 
	 * @param context
	 * @param dbName		数据库名
	 * @param tableList		数据库表的DLL语句
	 * @param version		数据库版本号
	 */
	public BaseDateBase(Context context,String dbName,List<Map<String, String>> tableList,int version) {
		super(context, dbName, null, version);
		this.tableList=tableList;
	}

	@Override
	/**
	 * 此方法在第一次启动时运行
	 */
	public void onCreate(SQLiteDatabase db) {
		StringBuffer buffer = new StringBuffer();
		for(Map<String, String> map: tableList){
			String Table_Create_DLL=map.get("Table_Create_DLL");
			buffer.append(Table_Create_DLL);
		}
		Log.i("数据库建表语句", buffer.toString());
		/* 数据库建表语句 */
		db.execSQL(buffer.toString());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		StringBuffer buffer = new StringBuffer();
		for(Map<String, String> map: tableList){
			String Table_Create_DLL=map.get("Table_Drop_DLL");
			buffer.append(Table_Create_DLL);
		}
		db.execSQL(buffer.toString());
		Log.i("数据库删除表语句", buffer.toString());
		onCreate(db);
	}

}
